//
//  CategoryLeftCell.m
//  陶瓷
//
//  Created by 王戈 on 15/6/7.
//  Copyright (c) 2015年 王戈. All rights reserved.
//

#import "CategoryLeftCell.h"

@interface CategoryLeftCell ()

@property (nonatomic, strong) UIView *grayLine;

@end

@implementation CategoryLeftCell

- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        
        _grayLine = [[UIView alloc] init];
        _grayLine.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_grayLine];
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _grayLine = [[UIView alloc] init];
        _grayLine.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_grayLine];
    }
    return self;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifier = @"CategoryLeftCell";
    // 1.取缓存中取
    CategoryLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建cell
    if (cell == nil) {
        cell = [[CategoryLeftCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    
    UIView *selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds];
    selectedBackgroundView.backgroundColor = [UIColor whiteColor];
    cell.selectedBackgroundView = selectedBackgroundView;
    cell.backgroundColor = TCMainBGColor;
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = IS_IPHONE_6_OR_MORE ? [UIFont systemFontOfSize:17] : [UIFont systemFontOfSize:14];
    
    //
    //    cell.textLabel.font =
    
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    self.textLabel.textColor = selected ? TCMainBGColor : [UIColor whiteColor];
}

- (void)setCategory:(CategoryModel *)category {
    _category = category;
    
    NSMutableString *string = [category.Name mutableCopy];
    NSRange range = NSMakeRange(0, string.length - 1);
    [string replaceOccurrencesOfString:@"|" withString:@"\n" options:NSLiteralSearch range:range];
    
    self.textLabel.text = string;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _grayLine.frame = CGRectMake(0,self.height - 0.5 , self.width, 0.5);
    self.textLabel.centerX = self.width/2;
}
@end
